package com.nexgo.payment.trans.balance;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.nexgo.payment.R;
import com.nexgo.payment.action.queryresp.QueryRespFragment;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.entity.TransData;
import com.nexgo.payment.trans.AbsTransActivity;
import com.nexgo.payment.util.ActivityUtils;

/**
 * 余额查询
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年8月21日
 */
public class BalanceActivity extends AbsTransActivity<BalanceContract.Presenter> implements BalanceContract.View {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new BalancePresenter(this, Repository.getInstance());
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    @Override
    public void showQueryResp(TransData transData) {
        QueryRespFragment queryRespFragment = QueryRespFragment.newInstance(transData);
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), queryRespFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), queryRespFragment, R.id.contentFrame);
        }
    }

    public static Intent newInstance(Context context) {
        return new Intent(context, BalanceActivity.class);
    }
}
